#!/usr/bin/perl
# Copyright (C) 2006, 2007  Stephane Alnet
# 
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
# 

#
# For more information visit http://carrierclass.net/
#

package CCNCore::spool::cdn_downstream_low_configuration;
use strict; use warnings;

=pod

    This is ran on a CDN node to distribute the configurations downstream
    to the end servers.

    Note how we use the local ticket to store the 
    callback information we received from the GUI Node so that we can
    notify the GUI node once the downstream (low) process is completed.
    (The notification itself is done in a generic way inside wait.pm.)

=cut

our $D;

sub run
{
    my $ticket   = pop;
    my $callback = pop;
    
    my $what = shift;
    my $target_pk = shift; # Optional server.pk

    use CCNCore::IPC::Ticket;
    my $t2 = new CCNCore::IPC::Ticket;
    $t2->add_context('callback',$callback);
    $t2->add_context('ticket',$ticket);

    # Create the rsync activity towards the edge-nodes and spool them.
    use CCNCore::Provisioning::Local;
    my $p = new CCNCore::Provisioning::Local;
    my $n;

    use CCNCore::Provision::CDN::distribute_configuration;
    $n = new CCNCore::Provision::CDN::distribute_configuration($p);

    my $count = $n->distribute_low($t2,$target_pk);
    # distribute_low() finishes with a "wait".
}
1;